par(mfrow=c(2, 2))
data5_1 <- read.csv("data/习题数据（基于R，EXCEL格式）/csv/E5_1.csv")
ts_volume <- ts(data5_1$volume)

# 时序图
plot(ts_volume, type="o", pch=5, col='#39CBB4')

# 一阶差分
dif_volume<-diff(ts_volume)
plot(dif_volume, type="o", pch=5, col='#39CBB4')

# ADF检验，平稳性检验
# install.packages("aTSA")
library(aTSA)
adf.test(dif_volume, nlag=3)

# 白噪声，纯随机检验
for( k in 1:3) print(Box.test(dif_volume, lag=6*k, type="Ljung-Box"))

# 自相关图
acf(dif_volume, lag.max=30)
pacf(dif_volume, lag.max=30)


# 拟合模型
# AR(1)
model11 <- arima(ts_volume, order=c(1, 1, 0), method="ML", transform.pars=F)
# MA(1)
model11 <- arima(ts_volume, order=c(0, 1, 1), method="ML", transform.pars=F)


# 模型显著性检验
tsdiag(model1)
tsdiag(model2)
model1
model2
data.frame(AIC(model1), AIC(model2), BIC(model1), BIC(model2))

# 预测未来10期
forecast(model1, h = 5)
